{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "BballQA"

// By ArtemQa146

const
    Baseballman = 31@
    Baseballman_2 = 30@
    ball_obj = 29@
    ball_render = 28@
    process = 27@
end

0085: 5@ = 0@ // (int)

        
        if and
            0EEA: locate_char_distance_to_coordinates $player_actor pos -2307.1387 206.304 35.3056 radius 100.0
            not locate_char_distance_to_coordinates $player_actor pos -2307.1387 206.304 35.3056 radius 30.0
        then
            0@ = true
            1@ = -2307.1387
            2@ = 206.304
            3@ = 35.3056
            4@ = 130.7969
        end
        
        if and
            0EEA: locate_char_distance_to_coordinates $player_actor pos 1383.2197 2184.4348 11.0234 radius 100.0
            not locate_char_distance_to_coordinates $player_actor pos 1383.2197 2184.4348 11.0234 radius 30.0
        then
            0@ = true
            1@ = 1383.2197
            2@ = 2184.4348
            3@ = 11.0234
            4@ = 133.4601
        end
        
        if
            0E4D: random_percent 5@
        then
        else
            repeat
            wait 0
            until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1@ 2@ 3@ radius 150.0
            0A93: terminate_this_custom_script
        end
    
    
        if
            0@ == true
        then
        
            repeat
            wait 0
            04ED: load_animation  "PedEventsMod"
            until 04EE:   animation "PedEventsMod" loaded
            
            model.Load(170)
            model.Load(3065)
            model.Load(96)
            model.Load(336)
            if
                not model.Available(170)
            then
                repeat
                wait 0
                model.Load(170)
                until model.Available(170)
            end
            if
                not model.Available(3065)
            then
                repeat
                wait 0
                model.Load(3065)
                until model.Available(3065)
            end
            if
                not model.Available(96)
            then
                repeat
                wait 0
                model.Load(96)
                until model.Available(96)
            end
            if
                not model.Available(336)
            then
                repeat
                wait 0
                model.Load(336)
                until model.Available(336)
            end
            038B: load_requested_models
            009A: Baseballman = create_actor_pedtype 4 model 96 at 1@ 2@ 3@
            0173: set_actor Baseballman Z_angle_to 4@
            04C4: store_coords_to 1@ 2@ 3@ from_actor Baseballman with_offset 0.0 12.0 0.0
            009A: Baseballman_2 = create_actor_pedtype 4 model 170 at 1@ 2@ 3@
            4@ += 183.0
            0173: set_actor Baseballman_2 Z_angle_to 4@
            01B2: give_actor Baseballman weapon 5 ammo 1 // Load the weapon model before using this
            model.Destroy(170)
            model.Destroy(96)
            model.Destroy(336)
            0E24: fix_char Baseballman ground 1 brightness 1 and_fade_in 0
            0E24: fix_char Baseballman_2 ground 1 brightness 1 and_fade_in 0
            0812: AS_actor Baseballman perform_animation "bball_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
            0812: AS_actor Baseballman_2 perform_animation "bball_throw2" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
            0E2E: create_render_object_to_char_bone Baseballman_2 model 3065 bone 25 offset 0 0 0 rotation 0 0 0 store_to ball_render
            0E01: create_object_no_save 3065 at 0.0 0.0 0.0 offset 0 ground 0 to ball_obj
            0E37: set_render_object_scale ball_render 0.4 0.4 0.4
            08D2: object ball_obj scale_model 0.4
            model.Destroy(3065)
            timera = 0
            process = 0
            04C4: store_coords_to 10@ 11@ 12@ from_actor Baseballman with_offset 0.0 0.0 0.0
            
            repeat
            wait 0
            if and
                056D:   actor Baseballman defined
                056D:   actor Baseballman_2 defined
            then
            
                if or
                    not locate_char_distance_to_char $player_actor char Baseballman radius 120.0
                    not locate_char_distance_to_char $player_actor char Baseballman_2 radius 120.0
                    051A:   actor Baseballman damaged_by_actor $PLAYER_ACTOR
                    0118:   actor Baseballman dead
                    051A:   actor Baseballman_2 damaged_by_actor $PLAYER_ACTOR
                    0118:   actor Baseballman_2 dead
                    not $ACTIVE_INTERIOR == 0
                then
                    01C2: remove_references_to_actor Baseballman // Like turning an actor into a random pedestrian
                    01C2: remove_references_to_actor Baseballman_2 // Like turning an actor into a random pedestrian
                    repeat
                    wait 0
                    until not locate_char_distance_to_coordinates $player_actor pos 10@ 11@ 12@ radius 150.0
                    break
                end
                
                080E: get_actor Baseballman ped_event_to 1@
                080E: get_actor Baseballman_2 ped_event_to 2@
                if or
                    1@ == 49
                    1@ == 9
                    2@ == 49
                    2@ == 9
                then
                    01C2: remove_references_to_actor Baseballman // Like turning an actor into a random pedestrian
                    01C2: remove_references_to_actor Baseballman_2 // Like turning an actor into a random pedestrian
                    repeat
                    wait 0
                    until not locate_char_distance_to_coordinates $player_actor pos 10@ 11@ 12@ radius 150.0
                    break
                end
                
                080E: get_actor Baseballman ped_event_to 1@
                080E: get_actor Baseballman_2 ped_event_to 2@
                if or
                    1@ == 15
                    1@ == 31
                    1@ == 59
                    2@ == 15
                    2@ == 31
                    2@ == 59
                then
                    01C2: remove_references_to_actor Baseballman // Like turning an actor into a random pedestrian
                    01C2: remove_references_to_actor Baseballman_2 // Like turning an actor into a random pedestrian
                    repeat
                    wait 0
                    until not locate_char_distance_to_coordinates $player_actor pos 10@ 11@ 12@ radius 150.0
                    break
                end
                
                if or
                    0457:   player $PLAYER_CHAR aiming_at_actor Baseballman
                    0457:   player $PLAYER_CHAR aiming_at_actor Baseballman_2
                then
                    0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                    0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                    if or
                        2@ == 1 //  
                        2@ == 3 //   (  ..)
                    then
                        01C2: remove_references_to_actor Baseballman // Like turning an actor into a random pedestrian
                        01C2: remove_references_to_actor Baseballman_2 // Like turning an actor into a random pedestrian
                        repeat
                        wait 0
                        until not locate_char_distance_to_coordinates $player_actor pos 10@ 11@ 12@ radius 150.0
                        break
                    end
                end

            
            
                if and
                    0EE4: locate_char_distance_to_char $player_actor char Baseballman radius 40.0
                    timera > 10000
                then
                    0615: define_AS_pack_begin 1@
                    0812: AS_actor -1 perform_animation "bball_hit" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                    0812: AS_actor -1 perform_animation "bball_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                    0616: define_AS_pack_end 1@
                    0618: assign_actor Baseballman to_AS_pack 1@
                    061B: remove_references_to_AS_pack 1@
                    0615: define_AS_pack_begin 1@
                    0812: AS_actor -1 perform_animation "bball_throw1" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                    0812: AS_actor -1 perform_animation "bball_throw2" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                    0616: define_AS_pack_end 1@
                    0618: assign_actor Baseballman_2 to_AS_pack 1@
                    061B: remove_references_to_AS_pack 1@
                    timera = 0
                end
                
                if
                    0611:   actor Baseballman_2 performing_animation "bball_throw1"
                then
                    0613: 1@ = actor Baseballman_2 animation "bball_throw1" time
                    if and
                        1@ > 0.6
                        process == 0
                    then
                        04C4: store_coords_to 1@ 2@ 3@ from_actor Baseballman_2 with_offset 0.0 0.5 0.0
                        01BC: put_object ball_obj at 1@ 2@ 3@
                        04C4: store_coords_to 1@ 2@ 3@ from_actor Baseballman_2 with_offset 0.0 1.5 0.03
                        0815: put_object ball_obj at 1@ 2@ 3@  and_keep_rotation
                        05A1: set_object ball_obj rotation_velocity_about_an_axis 0.0 0.0 1.0 through_center_of_body
                        0619: enable_actor Baseballman collision_detection 0
                        process = 1
                        0E31: set_render_object_visible ball_render 0
                    end
                    0613: 1@ = actor Baseballman_2 animation "bball_throw1" time
                    if and
                        1@ > 0.67
                        process == 1
                    then
                        if
                            0E4D: random_percent 50
                        then
                            04C4: store_coords_to 1@ 2@ 3@ from_actor Baseballman with_offset 0.0 0.5 0.0
                            01BC: put_object ball_obj at 1@ 2@ 3@
                            04C4: store_coords_to 1@ 2@ 3@ from_actor Baseballman with_offset -0.5 1.1 0.02
                            0815: put_object ball_obj at 1@ 2@ 3@  and_keep_rotation
                            process = 2
                        else
                            process = 2
                        end
                    end
                else
                    if or
                        process == 1
                        process == 2
                    then
                        01BC: put_object ball_obj at 0.0 0.0 0.0
                        0E31: set_render_object_visible ball_render 1
                        0619: enable_actor Baseballman collision_detection 1
                        process = 0
                    end
                end

                
            else
                break
            end
            until not player.Defined(0)
            04EF: release_animation "PedEventsMod"
            if 056D:   actor Baseballman defined
            then 01C2: remove_references_to_actor Baseballman // Like turning an actor into a random pedestrian
            end
            if 056D:   actor Baseballman_2 defined
            then 01C2: remove_references_to_actor Baseballman_2 // Like turning an actor into a random pedestrian
            end
            if 03CA:   object ball_obj exists
            then 01C4: remove_references_to_object ball_obj // This object will now disappear when the player looks away
            end
        end

0A93: terminate_this_custom_script
